package com.xy.blog.core.service;

import com.xy.blog.core.exception.BaseException;
import com.xy.blog.core.springmvc.result.page.PageReq;
import com.xy.blog.core.springmvc.result.page.PageResp;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author zanhonglei
 * @version V1.0
 * @Description: Service 基础
 * @date 2020/3/5
 */
public interface IBaseService<QUERY, BO> {

    /**
     * 分页查询
     * @param req
     * @return
     * @throws BaseException
     */
    default PageResp<BO> listByPage(PageReq<QUERY> req) throws BaseException {
        return null;
    }

    /**
     * 保存
     * @param item
     * @throws BaseException
     */
    @Transactional(rollbackFor = Throwable.class)
    default void save(BO item) throws BaseException {

    }

    /**
     * 更新
     * @param item
     * @throws BaseException
     */
    @Transactional(rollbackFor = Throwable.class)
    default void update(BO item) throws BaseException {}

    /**
     * 删除
     * @param id
     * @throws BaseException
     */
    @Transactional(rollbackFor = Throwable.class)
    default void deleteById(Long id) throws BaseException {}

    /**
     * 根据ID查询一个
     * @param id
     * @return
     * @throws BaseException
     */
    default BO getById(Long id) throws BaseException {
        return null;
    }

}
